﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Threading;

namespace Test.Web {
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1 {
        Random r = new Random();
        [OperationContract]
        public string Welcome() {
            // 在此处添加操作实现
            Thread.Sleep(r.Next(1000, 5000));
            var s = r.NextDouble();
            if (s > 0.3d) throw new Exception("the string length too long...");
            return s.ToString();
        }
        [OperationContract]
        public int Add(int a, int b) {
            Thread.Sleep(r.Next(1000, 5000));
            return a + b;
        }
        [OperationContract]
        public int Multiply(int a, int b) {
            var rr = default(int);
            rr = a * b;
            Thread.Sleep(r.Next(1000, 2000));
            return rr;
        }
        [OperationContract]
        public int Subtract(int a, int b) {
            var rr = default(int);
            rr = a - b;
            Thread.Sleep(r.Next(1000, 2000));
            return rr;
        }
        [OperationContract]
        public double Division(int a, int b) {
            var rr = default(double); 
            rr=a/b;
            Thread.Sleep(r.Next(1000, 2000));
            return rr;
        }
    }
}
